<?php

namespace App\Http\Validate\OpenShop\InvestmentPromotion;

use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Enums\OpenShop\InvestmentPromotion\UserBaseInfoEnum;
use App\Enums\OpenShop\InvestmentPromotion\UserOrderEnum;
use App\Http\Validate\BaseValidate;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserBaseInfoModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserContractModel;
use App\Service\OpenShop\Feishu\ConfigService;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;


/**
 * [ open_shop_user_base_info 招商加盟 - 用户基础信息 ] - 校验规则
 *
 * @UserBaseInfoValidate
 * @package App\Http\Controllers
 * @date 2022/02/28 06:48:03
 * @author GreenLeaf <786407418@qq.com>
 */
class PlaceholderValidate extends BaseValidate
{

    /**
     * 注册校验规则
     */
    public static function registerValidateRules(): void
    {

    }

//    /**
//     * 预处理参数
//     *
//     * @param array $data
//     * @return array
//     */
//    public static function beforeValidate(array $data): array
//    {
//        $data = collect($data)->filter(function ($v, $k) {
//
//            if ($v === "" && !in_array($k, [
//                    "shopBudget",
//                    "remarkMobile1",
//                    "remarkMobile2",
//                    "postCode",
//                    "shopCityCode",
//                    "shopDistrictCode",
//                    "chooseShopCityCode",
//                    "chooseShopDistrictCode",
//                    "cardAccountName",
//                    "cardBankName",
//                    "cardNo",
//                ])) {
//                return false;
//            }
//            return true;
//        })->toArray();
//        return parent::beforeValidate($data); // TODO: Change the autogenerated stub
//    }

    /**
     * 获取规则信息
     *
     * @param array $fields
     * @return string[]
     */
    public static function getRules(array $fields = []): array
    {
        return self::getActuallyRules([
            'isPlaceholder'   => 'bail|required|in:0,1',
            'longitude'       => 'exclude_unless:isPlaceholder,1|required',
            'latitude'        => 'exclude_unless:isPlaceholder,1|required',
            'siteAddress'     => 'exclude_unless:isPlaceholder,1|required',
            'provinceCode'    => 'exclude_unless:isPlaceholder,1|required',
            'cityCode'        => 'exclude_unless:isPlaceholder,1|required',
            'areaCode'        => 'exclude_unless:isPlaceholder,1|required',
            'cityArea'        => 'exclude_unless:isPlaceholder,1|required',
            'address'         => 'exclude_unless:isPlaceholder,1|required',
            'placeholderTime' => 'exclude_unless:isPlaceholder,1|required',
        ], $fields);
    }

    /**
     * @var array|string[]
     */
    public static array $validateMsg = [
    ];

    /**
     * @var array|string[]
     */
    public static array $attributes = [
        'isPlaceholder' => '预占点位',
    ];

    /**
     * 创建校验
     *
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function insertValidate(array $requestParams): array
    {
        return self::baseValidate(
            $requestParams,
            collect(self::getRules())->except(['orderNo'])->keys()->toArray(),
            null,
            null,
            self::getValidateMsg()
        );
    }

    /**
     * 更新校验
     *
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function updateValidate(array $requestParams): array
    {
        return self::baseValidate(
            $requestParams,
            collect(self::getRules())->except(['orderNo'])->keys()->toArray(),
            null,
            null,
            self::getValidateMsg()
        );
    }


    /**
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function detailValidate(array $requestParams): array
    {
        return self::baseValidate($requestParams, ['orderNo']);
    }

    /**
     * @param array $requestParams
     * @return array
     * @throws ValidationException
     */
    public static function orderBaseInfoUpdateValidate(array $requestParams): array
    {
        return self::baseValidate(
            $requestParams,
            [
                "shopProvinceCode",
                "shopCityCode",
                "shopDistrictCode",
                "shopAddressPrefix",
                "chooseAddressReason",
                "isSelfWithAddress",
                "chooseShopProvinceCode",
                "chooseShopCityCode",
                "chooseShopDistrictCode",
                "chooseShopAddressPrefix",
                "shopName",
                "shopAddress"
            ],
            null,
            null,
            self::$attributes
        );
    }
}
